package com.chanjiedata.changbs.module.main;

/**
 * 文件名 : ShopShareProfitActivity
 * 创建者 : MangoWang
 * 创建日期 : 2019/12/3 13:43
 * 微信 : MangoWaWang
 * 邮箱 : 763482205@qq.com
 * 描述 : TODO
 */

import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;

import com.chanjiedata.changbs.R;
import com.chanjiedata.changbs.base.BaseActivity;
import com.chanjiedata.changbs.net.Apis;
import com.chanjiedata.changbs.net.NetworkManager;
import com.chanjiedata.changbs.net.interfaces.OnRequestCallBack;
import com.chanjiedata.changbs.proto.Mystock;
import com.chanjiedata.changbs.utlis.StatusBarUtil;
import com.google.protobuf.InvalidProtocolBufferException;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ShopShareProfitActivity extends BaseActivity {


    @BindView(R.id.back_tv)
    TextView backTv;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_company_name)
    TextView tvCompanyName;
    @BindView(R.id.tv_sn_code)
    TextView tvSnCode;
    @BindView(R.id.tv_goods_name)
    TextView tvGoodsName;
    @BindView(R.id.tv_cloud_pay)
    TextView tvCloudPay;
    @BindView(R.id.tv_credit_card)
    TextView tvCreditCard;
    @BindView(R.id.tv_bank_card)
    TextView tvBankCard;
    @BindView(R.id.tv_fast_pay)
    TextView tvFastPay;
    @BindView(R.id.tv_code_pay)
    TextView tvCodePay;
    @BindView(R.id.tv_bank_card_top)
    TextView tvBankCardTop;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop_share_profit);
        ButterKnife.bind(this);
        StatusBarUtil.setStatusBarLightMode(this, Color.parseColor("#ffffff"), true);
        tvTitle.setText(getIntent().getStringExtra("title"));
        initListener();
        initData();
    }

    private void initData() {

        Mystock.MyProductRateInfo.Builder builder = Mystock.MyProductRateInfo.newBuilder();
        builder.setGoodsId(getIntent().getStringExtra("goods_id"))
                .setSnCode(getIntent().getStringExtra("sn_code"));

        NetworkManager.INSTANCE.post(Apis.myProductRateInfo, builder.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) throws InvalidProtocolBufferException {
                setViewData(response);
            }

            @Override
            public void onError(int errorCode, String errorMessage) {

            }
        });
    }


    private void initListener() {
        backTv.setOnClickListener(view -> {
            finish();
        });
    }


    private void setViewData(byte[] response) throws InvalidProtocolBufferException {
        Mystock.MyProductRateInfo.MCRateInfo data = Mystock.MyProductRateInfo.parseFrom(response).getMCRateInfo();
        tvSnCode.setText("SN号:" + data.getSnCode());
        tvCompanyName.setText(data.getGcName());
        tvGoodsName.setText(data.getGoodsName() + " " + data.getGoodsSerial());
        tvCloudPay.setText(data.getCloudMerchantRate() + "%");
        tvCreditCard.setText(data.getLineCardMerchantRate() + "%");
        tvBankCard.setText(data.getBankCardMerchantRate() + "%");
        tvFastPay.setText(data.getQuickPayMerchantRate() + "%");
        tvCodePay.setText(data.getScaveCodeMerchantRate() + "%");
        tvBankCardTop.setText(data.getBankCardMerchantRateTop());
    }


}
